package org.hot100_2;

import java.util.HashSet;

public class leetcode3 {
    public int lengthOfLongestSubstring(String s){

        int longest = 0;

        int left,right;

        int n = s.length();

        HashSet<Character> hashSet = new HashSet<>();

        for ( left=0 ; left <n; left++) {
            right=left;

            while (right<n && !hashSet.contains(s.charAt(right))){
                hashSet.add(s.charAt(right));
                right++;
            }
            longest=Math.max(longest,right-left);
            hashSet.clear();
        }

        return longest;
    }
}
